using System;
using System.Collections.Generic;
using System.Text;
using XinBang.Entity;
using XinBang.DAL;

namespace XinBang.BLL
{
    public class GoodsStrategyBL
    {
        private IGoodsStrategyDA<GoodsStrategy> gsd = BusinessLogicFactory.GetGoodsStrategyDA();
        private GoodsBL gb = new GoodsBL();

        public bool IsExistByStrategyIdGoodsId(int p, int gooid)
        {
            return GetGoodsStrategyByStrategyIdGoodsId(p, gooid) == null ? false : true;
        }

        public GoodsStrategy GetGoodsStrategyByStrategyIdGoodsId(int p, int gooid)
        {
            return gsd.GetGoodsStrategyByStrategyIdGoodsId(p,gooid);
        }

        public void InsertGoodsStrategy(SaleStrategy saleStrategy, int gooid)
        {
            if (!IsExistByStrategyIdGoodsId(saleStrategy.Salid, gooid))
            {
                GoodsStrategy gs = new GoodsStrategy();
                gs.Gooid = gb.GetGoodsById(gooid);
                gs.Salid = saleStrategy;
                gsd.Insert(gs);
            }
        }


        public void DeleteGoodsStrategy(SaleStrategy saleStrategy, int gooid)
        {
            if (IsExistByStrategyIdGoodsId(saleStrategy.Salid, gooid))
            {
                gsd.Delete(GetGoodsStrategyByStrategyIdGoodsId(saleStrategy.Salid,gooid));
            }
        }

        public IList<Goods> GetGoodsListByStrategyId(int sid,int n)
        {
            return gsd.GetTopNGoodsListByStrategyId(sid,n);
        }
    }
}
